import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author wq3stone
 */
public class InitServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PreparedStatement ps = null;
        Connection conn = null;
        try {
            conn = DBUtil.getConnection();

            String sql1 = "drop table if exists tb_sum";
            ps = conn.prepareStatement(sql1);
            ps.execute();
            String sql2 = "create table tb_sum (id int(1),num int(10))";
            ps = conn.prepareStatement(sql2);
            ps.execute();
            String sql3 = "insert into tb_sum values(1,0)";
            ps = conn.prepareStatement(sql3);
            ps.executeUpdate();
            String sql4 = "insert into tb_sum values(2,0)";
            ps = conn.prepareStatement(sql4);
            ps.executeUpdate();

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
